package cn.kgc.controller.logic.annunciate;
import cn.kgc.pojo.Notity;
import cn.kgc.service.annunciate.NotityService;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.sql.Date;


@Controller
@RequestMapping("/si")
public class Zyn_controller {

    @Resource
    private NotityService notityService;


    //分页查询
    @RequestMapping("/sle")
    @ResponseBody
    public String sel(@Param("currentPage") Integer currentPage,@Param("pageSize") Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        System.out.println("id"+currentPage);
        Page<Notity> sel1 = (Page<Notity>) notityService.selQxmbyId(currentPage);
        PageInfo p = new PageInfo(sel1,pageSize);
        System.out.println("p--------------"+p);
        return JSON.toJSONString(p);


    }

    //添加公告
    @RequestMapping("/save")
    @ResponseBody
    //String createDates
    public boolean save(@ModelAttribute Notity notity){
//        notity.setCreateDate(Date.valueOf(createDates));
        int insert = notityService.ADD(notity);
        System.out.println("insert"+insert);
        if (insert>0){
            return true;
        }
        return false;
    }

    //删除页面上的 保留数据库里的
    @RequestMapping("/upd")
    @ResponseBody
    public boolean upd(@RequestParam Integer id){
        boolean upd = notityService.upd(id);
        return  upd;
    }


    //单条查询
    @RequestMapping("/sa")
    public String as(@RequestParam int id, Model model){
        Notity i = notityService.sa(id);
        model.addAttribute("contact",i);
        return "/annunciate/zym_xiangqing";
    }

    //公告查看
    @RequestMapping("/zym-index")
    public String announcement() {
        return "annunciate/zym-index";
    }

}





